﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent(); 
            this.timer1.Interval = 10000;
            this.timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.button1_Click(null, null);
        }

		string m_lastid = "0";
		string m_lasttype = "0";
		Random m_random = new Random();

		Vlog.MsAccess m_db = new Vlog.MsAccess();

		private void button1_Click(object sender, EventArgs e)
		{
			label1.Text = DateTime.Now.ToLongTimeString();
			this.Text = DateTime.Now.ToLongTimeString();
			// http://www.futuremark.com/ticker.xml?lastid=11520974&lasttype=14&r=0.5
			double v_random = m_random.NextDouble();
			string v_url = String.Format("http://www.futuremark.com/ticker.xml?lastid={0}&lasttype={1}&r={2}", m_lastid, m_lasttype, v_random);
			Debug.WriteLine(v_url);

			string v_html = "";
			try
			{
				/*string*/
				v_html = getPage(v_url);
				////v_html = v_html.Replace("encoding=\"UTF-8\"", "encoding=\"UTF-16\"");
				//Debug.WriteLine(v_html);
				v_html = v_html.Replace("<cpu><unknown></cpu>", "<cpu>unknown</cpu>");
				System.Xml.XmlDocument v_xml = new System.Xml.XmlDocument();
				v_xml.Load(new System.IO.StringReader(v_html));

				//Debug.WriteLine(v_xml.OuterXml);
				//Debug.WriteLine(xmlToString(v_xml));

				System.Xml.XmlNodeList v_list = v_xml.SelectNodes("/ticker/items/item");

				int v_count = 0;
				foreach (System.Xml.XmlNode v_node in v_list)
				{
					v_count++;

					insertTicker(v_node);

					string v_id = getNodeElemInnerText(v_node, "id");
					string v_productid = getNodeElemInnerText(v_node, "productid");
					m_lastid = v_id;
					m_lasttype = v_productid;
				}
			}
#if (true)
			catch (Exception ex)
			{
				Debug.WriteLine("v_html=[["+v_html+"]]");
				Debug.WriteLine(ex.StackTrace.ToString());
				Debug.WriteLine(ex.Message);
			}
#endif
			finally
			{
			}

		}


		protected string modifyString(string x)
		{
			x = x.Replace(" (R) ", " ");
			x = x.Replace("(R) ", " ");
			x = x.Replace("(R)", " ");
			x = x.Replace("(tm)", "(TM)");
			x = x.Replace(" (TM) ", " ");
			x = x.Replace("(TM) ", " ");
			x = x.Replace("(TM)", " ");
			StringBuilder sb = new StringBuilder();
			foreach (char c in x)
			{
				if (((UInt16)c) > 127) continue;
				sb.Append(c);
			}
			return sb.ToString().Trim();
		}

		////System.Data.OleDb.OleDbConnection connection = null;

		protected string getGrade(string v_print)
		{
			System.Data.OleDb.OleDbCommand command = m_db.MakeCommand(
				"SELECT grade from tbl_print where print = ?;",
				v_print
				);
			object v_grade = command.ExecuteScalar();
			if (v_grade == null || v_grade.GetType() == typeof(System.DBNull))
			{
				return "none";
			}
			return (string)v_grade;
		}

		protected bool isKnown(string v_print)
		{
			//string query1 = "SELECT count(*) from tbl_invalid_cpu where cpu = ?;";
			System.Data.OleDb.OleDbCommand command1 = m_db.MakeCommand(
				"SELECT count(*) from tbl_invalid_cpu where cpu = ?;",
				v_print
				);
			int count1 = (int)command1.ExecuteScalar();
			if (count1 > 0)
			{
				return true;
			}
			System.Data.OleDb.OleDbCommand command2 = m_db.MakeCommand(
				"SELECT count(*) from tbl_invalid_vga where vga = ?;",
				v_print
				);
			int count2 = (int)command2.ExecuteScalar();
			if (count2 > 0)
			{
				return true;
			}
			System.Data.OleDb.OleDbCommand command = m_db.MakeCommand(
				"SELECT count(*) from tbl_print where print = ?;",
				v_print
				);
			int count = (int)command.ExecuteScalar();
			if (count > 0)
			{
				return true;
			}
			return false;
		}

		protected void registerBestVga(ticker v_ticker)
		{
			if (v_ticker.v_test != "F3D_06")
			{
				return;
			}
			try
			{
				string v_cpu_grade = getGrade(v_ticker.v_cpu);
				string v_vga_grade = getGrade(v_ticker.v_vga);
				string queryMax = "SELECT score from tbl_best_vga where vga = ? and cpu_grade= ?;";
				System.Data.OleDb.OleDbCommand commandInvalidVga = m_db.MakeCommand(queryMax, v_ticker.v_vga_orig, v_cpu_grade);
				object v_max = commandInvalidVga.ExecuteScalar();
				if (v_max == null || v_max.GetType() == typeof(System.DBNull))
				{
					Debug.WriteLine("    (v_max == null)");
					string queryString = "";
					queryString += "INSERT INTO tbl_best_vga (";
					queryString += " vga";
					queryString += ",vga_grade";
					queryString += ",cpu_grade";
					queryString += ",cpu";
					queryString += ",times";
					queryString += ",score";
					queryString += ",localtime";
					queryString += ",country";
					queryString += ")";
					queryString += "VALUES(?,?,?,?,1,?,?,?);";
					System.Data.OleDb.OleDbCommand command = m_db.MakeCommand(
						queryString,
						v_ticker.v_vga_orig,
						v_vga_grade,
						v_cpu_grade,
						v_ticker.v_cpu_orig,
						v_ticker.v_score,
						v_ticker.v_ts_local,
						v_ticker.v_country
						);
					command.ExecuteNonQuery();
				}
				else if (v_ticker.v_score > (int)v_max)
				{
					Debug.WriteLine("    (v_max != null)[A]");
					string queryString = "";
					queryString += "UPDATE tbl_best_vga SET ";
					queryString += " vga_grade = ? ";
					queryString += ",cpu_grade = ? ";
					queryString += ",cpu = ? ";
					queryString += ",times = times + 1 ";
					queryString += ",score = ? ";
					queryString += ",localtime = ? ";
					queryString += ",country = ? ";
					queryString += "WHERE vga = ? and cpu_grade = ?;";
					System.Data.OleDb.OleDbCommand command = m_db.MakeCommand(
						queryString,
						v_vga_grade,
						v_cpu_grade,
						v_ticker.v_cpu_orig,
						v_ticker.v_score,
						v_ticker.v_ts_local,
						v_ticker.v_country,
						v_ticker.v_vga_orig,
						v_cpu_grade
						);
					command.ExecuteNonQuery();
				}
				else
				{
					Debug.WriteLine("    (v_max != null)[B]");
					string queryString = "";
					queryString += "UPDATE tbl_best_vga SET ";
					queryString += " times = times + 1 ";
					queryString += "WHERE vga = ? and cpu_grade = ?;";
					System.Data.OleDb.OleDbCommand command = m_db.MakeCommand(
						queryString,
						v_ticker.v_vga_orig,
						v_cpu_grade
						);
					command.ExecuteNonQuery();
				}
				System.Data.OleDb.OleDbCommand commandLastUpdate = m_db.MakeCommand(
					//"UPDATE tbl_best_vga SET updated=now() WHERE vga = ? and cpu_grade = ?;", v_ticker.v_vga_orig, v_cpu_grade
					"UPDATE tbl_best_vga SET updated=now() WHERE vga = ?;", v_ticker.v_vga_orig
					);
				commandLastUpdate.ExecuteNonQuery();
			}
			catch (Exception ex)
			{
			}
		}

		protected bool insertTicker(System.Xml.XmlNode v_node)
		{
			ticker v_ticker = node2ticker(v_node);
			if (v_ticker == null) return false;

#if (false)
			if (v_ticker.v_test == "F3D_06")
			{
			}
			else
			{
				return false;
			}
#endif

			Debug.WriteLine("    TRY: score=" + v_ticker.v_score + " | " + v_ticker.v_cpu + " | " + v_ticker.v_vga + " | " + v_ticker.v_mem + "MB | " + v_ticker.v_os);

			bool invalid = false;


			if (!isKnown(v_ticker.v_cpu))
			{
				v_ticker.v_cpu = "+" + v_ticker.v_cpu;
			}
			if (!isKnown(v_ticker.v_vga))
			{
				v_ticker.v_vga = "+" + v_ticker.v_vga;
			}

			string queryInvalidCpu = "SELECT count(*) from tbl_invalid_cpu where cpu = ? and del = 0;";
			System.Data.OleDb.OleDbCommand commandInvalidCpu = m_db.MakeCommand(
				queryInvalidCpu,
				v_ticker.v_cpu
				);
			int cpuCount = (int)commandInvalidCpu.ExecuteScalar();
			if (cpuCount > 0)
			{
				Debug.WriteLine("    [CPU Invalid]");
				v_ticker.v_cpu = "@" + v_ticker.v_cpu;
				invalid = true;
			}

			// Invalid VGA
			string queryInvalidVga = "SELECT count(*) from tbl_invalid_vga where vga = ? and del = 0;";
			System.Data.OleDb.OleDbCommand commandInvalidVga = m_db.MakeCommand(
				queryInvalidVga,
				v_ticker.v_vga
				);
			int vgaCount = (int)commandInvalidVga.ExecuteScalar();
			if (vgaCount > 0)
			{
				Debug.WriteLine("    [VGA Invalid]");
				v_ticker.v_vga = "@" + v_ticker.v_vga;
				invalid = true;
			}

#if (false)
			if (!invalid && Int32.Parse(v_score) < 10000)
			{
				Debug.WriteLine("--- [LOW Score]");
				return false;
			}
#endif


			try
			{
				if (v_ticker.v_score >= 20000) invalid = false;
				if (invalid)
				{
					if (v_ticker.v_cpu.StartsWith("@") && v_ticker.v_vga.StartsWith("@"))
					{
					}
					else
					{
						invalid = false;
					}
					if (v_ticker.v_cpu.StartsWith("+") || v_ticker.v_vga.StartsWith("+"))
					{
						invalid = false;
					}
				}
				//invalid = false; /**/
				string tbl_name = (invalid ? "tbl_ticker_minor" : "tbl_ticker");
				string queryString = "";
				queryString += "INSERT INTO " + tbl_name +" (";
				queryString += " productid";
				queryString += ",id";
				queryString += ",product";
				queryString += ",test";
				queryString += ",score";
				queryString += ",country";
				queryString += ",continent";
				queryString += ",localtime";
				queryString += ",cpu";
				queryString += ",speed";
				queryString += ",vga";
				queryString += ",os";
				queryString += ",mem";
				queryString += ",md5";
				queryString += ")";
				queryString += "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";



				System.Data.OleDb.OleDbCommand command = m_db.MakeCommand(
					queryString,
					Int32.Parse(v_ticker.v_productid),
					Int32.Parse(v_ticker.v_id),
					v_ticker.v_product,
					v_ticker.v_test,
					v_ticker.v_score,
					v_ticker.v_country,
					v_ticker.v_continent,
					v_ticker.v_ts_local,
					v_ticker.v_cpu,
					v_ticker.v_speed,
					v_ticker.v_vga,
					v_ticker.v_os,
					Int32.Parse(v_ticker.v_mem),
					v_ticker.v_md5
					);
				command.ExecuteNonQuery();
				//結果を表示
				if (!invalid && v_ticker.v_test.StartsWith("F3D"))
				{
					Debug.WriteLine("*** " + v_ticker.v_md5 + " : " + v_ticker.v_test + "=" + v_ticker.v_score);
					Debug.WriteLine("*** OK: " + v_ticker.v_cpu + " | " + v_ticker.v_vga + " | " + v_ticker.v_mem + "MB | " + v_ticker.v_os);
				}
				if (v_ticker.v_test == "F3D_06")
				{
					registerBestVga(v_ticker);
				}
				return true;
			}
			catch (Exception ex)
			{
				//Debug.WriteLine(ex.Message);
				return false;
			}
			finally
			{
				////connection.Close();
			}

		}

		protected string getPage(string url)
		{
			System.Net.WebRequest webreq = System.Net.WebRequest.Create(url);
			System.Net.WebResponse webres = webreq.GetResponse();
			System.Text.Encoding enc = System.Text.Encoding.UTF8;
			System.IO.Stream st = webres.GetResponseStream();
			System.IO.StreamReader sr = new System.IO.StreamReader(st, enc);
			String html = sr.ReadToEnd();
			sr.Close();
			return html;
		}

		protected string getNodeElemInnerText(System.Xml.XmlNode node, string name)
		{
			System.Xml.XmlElement v_node_elem = node[name];
			string v_result = v_node_elem.InnerText;
			return v_result;
		}

		protected string xmlToString(System.Xml.XmlDocument xml)
		{
			StringBuilder v_sb = new StringBuilder();
			System.IO.StringWriter v_sw = new System.IO.StringWriter(v_sb);
			xml.Save(v_sw);
			return (v_sb.ToString());
		}

		protected string getMD5(string s)
		{
			//文字列をbyte型配列に変換する
			byte[] data = System.Text.Encoding.UTF8.GetBytes(s);

			//MD5CryptoServiceProviderオブジェクトを作成
			System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
			//ハッシュ値を計算する
			byte[] bs = md5.ComputeHash(data);
			//byte型配列を16進数の文字列に変換
			string result = BitConverter.ToString(bs).ToLower().Replace("-", "");
			return result;
		}

		private void Form1_Activated(object sender, EventArgs e)
		{
			this.button1_Click(null, null);
		}

		private void button2_Click(object sender, EventArgs e)
		{
#if (false)
			try
			{
				System.Data.OleDb.OleDbCommand command1 = new System.Data.OleDb.OleDbCommand("DROP TABLE tbl_ticker;", connection);
				command1.ExecuteNonQuery();
			}
			finally
			{
			}


			string queryString = "";
			queryString += "CREATE TABLE tbl_ticker (";
			queryString += " productid LONG";
			queryString += ",id LONG";
			queryString += ",test TEXT";
			queryString += ",localtime DATETIME";
			queryString += ",score LONG";
			queryString += ",cpu TEXT";
			queryString += ",speed LONG";
			queryString += ",vga TEXT";
			queryString += ",mem LONG";
			queryString += ",os TEXT";
			queryString += ",country TEXT";
			queryString += ",continent TEXT";
			queryString += ",product TEXT";
			queryString += ",md5 TEXT CONSTRAINT tbl_ticker_md5 UNIQUE";
			queryString += ",PRIMARY KEY (productid,id));";

			System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand(queryString, connection);
			command.ExecuteNonQuery();
#endif
		}

		protected ticker node2ticker(System.Xml.XmlNode v_node)
		{
			ticker v_ticker = new ticker();
			v_ticker.v_id = getNodeElemInnerText(v_node, "id");
			v_ticker.v_productid = getNodeElemInnerText(v_node, "productid");
			v_ticker.v_product = getNodeElemInnerText(v_node, "product");
			v_ticker.v_country = getNodeElemInnerText(v_node, "country");
			v_ticker.v_continent = getNodeElemInnerText(v_node, "continent");

			string v_time = getNodeElemInnerText(v_node, "time");
			long v_time_64 = Int64.Parse(v_time);
			DateTime v_ts_utc = new DateTime(1970, 1, 1).AddMilliseconds(v_time_64);
			DateTime v_ts_local = v_ts_utc.ToLocalTime();
			v_ticker.v_ts_local = v_ts_local;
			v_ticker.v_cpu = getNodeElemInnerText(v_node, "cpu");
			v_ticker.v_speed = Int32.Parse(getNodeElemInnerText(v_node, "cpuspeed"));
			v_ticker.v_vga = getNodeElemInnerText(v_node, "gpu");
			v_ticker.v_os = getNodeElemInnerText(v_node, "os");
			v_ticker.v_mem = getNodeElemInnerText(v_node, "mem");
			string v_score = getNodeElemInnerText(v_node, "score");
			v_ticker.v_test = v_ticker.v_product;
			if (v_ticker.v_product == "3DMark Vantage")
			{
				string v_first = v_score.Substring(0, 1);
				Int32 v_out;
				if (Int32.TryParse(v_first, out v_out))
				{
					v_ticker.v_test = "F3DV";
				}
				else
				{
					v_ticker.v_test = "F3DV_" + v_score.Substring(0, 1);
					v_score = v_score.Substring(1);
				}
			}
			else if (v_ticker.v_product == "PCMark Vantage")
			{
				string v_first = v_score.Substring(0, 1);
				Int32 v_out;
				if (Int32.TryParse(v_first, out v_out))
				{
					v_ticker.v_test = "FPCV";
				}
				else
				{
					v_ticker.v_test = "FPCV_" + v_score.Substring(0, 1);
					v_score = v_score.Substring(1);
				}
			}
			else
			{
				v_ticker.v_test = v_ticker.v_test.Replace("3DMark", "F3D_");
				v_ticker.v_test = v_ticker.v_test.Replace("PCMark", "FPC_");
			}
			v_ticker.v_score = Int32.Parse(v_score);

			if (v_ticker.v_test == "F3D_05")
			{
				return null;
			}
			// OS
			string v_os_mod = v_ticker.v_os;
			v_os_mod = v_ticker.v_os.Replace("Microsoft Windows ", "");
			v_os_mod = v_os_mod.Replace("Windows 7", "Win7");
			v_ticker.v_os = v_os_mod;
			// CPU
			string v_cpu_mod = v_ticker.v_cpu;
			v_cpu_mod = modifyString(v_cpu_mod);
			v_cpu_mod = v_cpu_mod.Replace(" @ ", " ");
			v_cpu_mod = v_cpu_mod.Replace(" - ", " ");
			v_cpu_mod = v_cpu_mod.Replace(" Processor", "");
			v_cpu_mod = v_cpu_mod.Replace(" processor", "");
			v_cpu_mod = v_cpu_mod.Replace(" CPU", "");
			v_cpu_mod = v_cpu_mod.Replace("Mobile Intel ", "Intel Mobile ");
			v_cpu_mod = v_cpu_mod.Replace("mobile AMD ", "AMD Mobile ");
			v_cpu_mod = v_cpu_mod.Replace("Mobile AMD ", "AMD Mobile ");
			v_cpu_mod = v_cpu_mod.Replace(" Extreme Edition", "");
			v_cpu_mod = v_cpu_mod.Replace(" Black Edition", "");
			v_cpu_mod = v_cpu_mod.Replace("Pentium? ", "Pentium ");
			v_cpu_mod = v_cpu_mod.Replace("Pentium?", "Pentium ");
			v_cpu_mod = v_cpu_mod.Replace("Intel Core2", "Intel Core 2");
			v_cpu_mod = v_cpu_mod.Replace("Dual-Core", "Dual Core");
			v_cpu_mod = v_cpu_mod.Replace("Triple-Core", "Triple Core");
			v_cpu_mod = v_cpu_mod.Replace("Quad-Core", "Quad Core");
			v_cpu_mod = v_cpu_mod.Replace("Six-Core", "Six Core");
			if (v_cpu_mod.StartsWith("Athlon")
				||
				v_cpu_mod.StartsWith("Duron"))
			{
				v_cpu_mod = "AMD " + v_cpu_mod;
			}
			if (v_cpu_mod.StartsWith("Dual Core "))
			{
				v_cpu_mod = v_cpu_mod.Replace("Dual Core ", "");
				v_cpu_mod = v_cpu_mod + " Dual Core";
			}
			if (v_cpu_mod.StartsWith("Triple Core "))
			{
				v_cpu_mod = v_cpu_mod.Replace("Triple Core ", "");
				v_cpu_mod = v_cpu_mod + " Triple Core";
			}
			if (v_cpu_mod.StartsWith("Quad Core "))
			{
				v_cpu_mod = v_cpu_mod.Replace("Quad Core ", "");
				v_cpu_mod = v_cpu_mod + " Quad Core";
			}
			if (v_cpu_mod.StartsWith("Six Core "))
			{
				v_cpu_mod = v_cpu_mod.Replace("Six Core ", "");
				v_cpu_mod = v_cpu_mod + " Six Core";
			}
			if (v_cpu_mod.StartsWith("Pentium"))
			{
				v_cpu_mod = "Intel " + v_cpu_mod;
			}
			if (v_cpu_mod.StartsWith("Celeron"))
			{
				v_cpu_mod = "Intel " + v_cpu_mod;
			}
			if (v_cpu_mod.StartsWith("Intel Core i7-"))
			{
				v_cpu_mod = v_cpu_mod.Replace("Intel Core i7-", "Intel Core i7 ");
			}
			if (v_cpu_mod.StartsWith("Intel Core i5 I5-"))
			{
				v_cpu_mod = v_cpu_mod.Replace("Intel Core i5 I5-", "Intel Core i5 ");
			}
			

			string[] v_ng_cpu = {
				"Missing CPU",
				"Missing",
				"Unknown Typ",
				"Unknown Type",
				"Unknown",
				"unknown",
				"AMD Unknown",
				"AMD Athlon",
				"AMD Athlon prosussor",
				"AMD Engineering Sample",
				"AMD Engineering Sample 00",
				"AMD Athlon X2 240",
				"AMD Athlon X2 245",
				"AMD Athlon X2 250",
				"AMD Phenom II X4 10",
				"AMD Phenom II X4 20",
				//"AMD Hammer Family - Model Unknown",
				"AMD Hammer Family Model Unknown",
				"AMD model unknown",
				"Intel Core 870 2.93GHz",
				"Intel Core 975 3.33GHz",
				"Intel Core i7 9200 2.67GHz",
				"Intel Core i7 9500 3.07GHz",
				"Intel Core 750 2.67GHz",
				"Intel Core 860 2.80GHz",
				"Intel Core 965 3.20GHz",
				"Intel Core Q 820 1.73GHz",
				"Intel Core Duo L2500 1.83GHz",
				"Intel Core Duo T2350 1.86GHz",
				"Intel Core Duo T2400 1.83GHz",
				"Intel Core Duo T2600 2.16GHz",
				"Intel Core Duo U2500 1.20GHz",
				"Intel Core 2 2.00GHz",
				"Intel Core 2 Duo 2.53GHz",
				"Intel Core 2 Duo 2.66GHz",
				"Intel Core 2 Duo 3.00GHz",
				"Intel Core 2 E7400 2.80GHz",
				"Intel Core 2 E7500 2.93GHz",
				"Intel Core 2 E8400 3.00GHz",
				"Intel Core 2 E8500 3.16GHz",
				"Intel Core 2 E8600 3.33GHz",
				"Intel Core 2 T5200 1.60GHz",
				"Intel Core 2 T7200 2.00GHz",
				"Intel Core 2 X6800 2.93GHz",
				"Intel Core 2 4300 1.80GHz",
				"Intel Core 2 4400 2.00GHz",
				"Intel Core 2 6300 1.86GHz",
				"Intel Core 2 6320 1.86GHz",
				"Intel Core 2 6400 2.13GHz",
				"Intel Core 2 6420 2.13GHz",
				"Intel Core 2 6600 2.40GHz",
				"Intel Core 2 6700 2.66GHz",
				"Intel Core 2 Extreme 2.26GHz",
				"Intel Core 2 Extreme 2.40GHz",
				"Intel Core 2 Quad",
				"Intel Core 2 Quad 2.13GHz",
				"Intel Core 2 Quad 2.40GHz",
				"Intel Core 2 Quad 2.66GHz",
				"Intel Core 2 Quad 2.93GHz",
				"Intel Core N270 1.60GHz",
				"Intel Core X 920 2.00GHz",
				"Intel Pentium III",
				"Intel Pentium Dual E2160 1.80GHz",
				"Intel Pentium Dual E2180 2.00GHz",
				"Intel Xeon 2.00GHz",
				"Intel Xeon 2.40GHz",
				"Intel Xeon 2.80GHz",
				"Intel Xeon 3.00GHz",
				"Intel Xeon 3.06GHz",
				"Intel Xeon 3.20GHz",
				"Intel Xeon 3.40GHz",
				"Intel Xeon 3.60GHz",
				"Intel Xeon 3.73GHz",
				"Intel Xeon 3.80GHz",
				"Intel Xeon X55500 .",
				"Intel Xeon 000 2.93GHz",
				"Pent`um Dqal-Core E5300 2.60GHz",
				"ThoroughBred",
				"mobile AMD Athlon XP-M 2600+",
			};
			List<string> v_ng_cpu2 = new List<string>(v_ng_cpu);
			if (v_ng_cpu2.Contains(v_cpu_mod.Trim()))
			{
				return null;
			}
			if (v_cpu_mod.StartsWith("Genuine Intel"))
			{
				return null;
			}
			if (v_cpu_mod.StartsWith("Unknown AMD:"))
			{
				return null;
			}
			v_ticker.v_cpu = v_cpu_mod.Trim();
			////v_ticker.v_cpu = v_cpu_mod;


			// VGA
			string v_vga_mod = v_ticker.v_vga;
			v_vga_mod = modifyString(v_vga_mod);
			v_vga_mod = v_vga_mod.Replace("NVIDIA GeForce", "GeForce");
			v_vga_mod = v_vga_mod.Replace("ATI Mobility Radeon", "Mobility Radeon");
			v_vga_mod = v_vga_mod.Replace("ATI Radeon", "Radeon");
			string[] v_ng_vga = {
				"Generic VGA",
				"2x Generic VGA",
				"Chipset Missing",
				"Radeon HD",
				"Mobility Radeon",
				"AMD Athlon Prosussor",
			};
			List<string> v_ng_vga2 = new List<string>(v_ng_vga);
			if (v_ng_vga2.Contains(v_vga_mod.Trim()))
			{
				return null;
			}
			v_ticker.v_vga = v_vga_mod.Trim();

			string md5source =
			v_ticker.v_test
			+ "|"
			+ v_ticker.v_country
			+ "|"
			+ v_ticker.v_score
			+ "|"
			+ v_ticker.v_score
			+ "|"
			+ v_ticker.v_speed
			+ "|"
			+ v_ticker.v_cpu
			+ "|"
			+ v_ticker.v_vga
			+ "|"
			+ v_ticker.v_mem
			+ "|"
			+ v_ticker.v_os
			;

			v_ticker.v_md5 = getMD5(md5source);
			v_ticker.v_cpu_orig = v_ticker.v_cpu;
			v_ticker.v_vga_orig = v_ticker.v_vga;

			return v_ticker;
		}

	}
	public class ticker
	{
		public string v_id;
		public string v_productid;
		public string v_product;
		public string v_test;
		public Int32 v_score;
		public string v_country;
		public string v_continent;
		public DateTime v_ts_local;
		public string v_cpu;
		public string v_cpu_orig;
		public Int32 v_speed;
		public string v_vga;
		public string v_vga_orig;
		public string v_os;
		public string v_mem;
		public string v_md5;
	}
}